﻿//using Mes.Pendant.CustomerManagements.Service;
using IdentityModel.OidcClient;
using Mes.Pendant.SupplierInterface;
using Mes.Pendant.SupplierInterface.SupplierDto;
using Mes.Pendant.SupplierManagements;
using Mes.Pendant.UnitMeasures;
using Microsoft.AspNetCore.Mvc;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace Mes.Pendant.Web.Controllers
{
    public class SupplierController : Controller
    {
        private readonly ISupplierService _supplierService;

        public SupplierController(ISupplierService supplierService)
        {
            _supplierService = supplierService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Add()
        {
            return View();
        }

        public async Task<int> AddSupplier(SupplierManagementDto supplierManagementDto)
        {
            var result = await _supplierService.AddSupplier(supplierManagementDto);
            return result;
        }

        public IActionResult SupplierList()
        {
            return View();
        }

        public IActionResult Update(int id)
        {
            ViewBag.id = id;
            return View();
        }

        public async Task<JsonResult> GetSupplierrList(string? supplierCode, string? supplierName, string? abbreviation, bool? state, int page = 1, int limit = 10)
        {
            var result = await _supplierService.GetSupplierrList(supplierCode, supplierName, abbreviation, state, page, limit);
            return Json(new { data = result.Queryable, count = result.RowCount, code = 0 });
        }

        public async Task<int> DeleteSupplier(int id)
        {
            var result = await _supplierService.DeleteSupplier(id);
            return result;
        }

        public async Task<JsonResult> GetSupplierInfo(int id)
        {
            var list = _supplierService.GetSupplierInfo(id);
            return Json(new { data = list.Result });

        }

        public async Task<int> UpdateSupplier(SupplierManagementDto supplierManagementDto)
        {
            var result = await _supplierService.UpdateSupplier(supplierManagementDto);
            return result;
        }
    }
}
